//
// Created by liushuai on 2020/1/31.
//
<<<<<<< HEAD:cxx/algorithm/src/rotate.cc
#include "rotate.h"
void rotate(vector<vector<int>>& matrix){
    int length = matrix.size();
    int span = length-1;
    int layers = length/2;
    int currentValue = 0;
    int nextValue = 0;
    for(int i=0;i<layers;i++){
        for(int j=i;j<span;j++){
            int headValue = matrix[i][j];

            currentValue = matrix[i][j];//--5
            nextValue = matrix[j][i+span];//--11
            matrix[j][i+span] = currentValue;//11==>5

            currentValue = nextValue;
            nextValue = matrix[i+span][i+span-j];//--16
            matrix[i+span][i+span-j] = currentValue;//16==>11

            currentValue = nextValue;//16
            nextValue = matrix[i+span-j][i];//
            matrix[i+span-j][i] = currentValue;//15==>16
            matrix[i][j] = nextValue;
        }
        span/=2;
    }



}
=======
#include "common.h"
namespace common {
void rotate(std::vector<std::vector<int>> &matrix) {
    int length = matrix.size();
    int span = length - 1;
    int layers = length / 2;
    int currentValue = 0;
    int nextValue = 0;
    for (int i = 0; i < layers; i++) {
        for (int j = i; j < span; j++) {
            int headValue = matrix[i][j];

            currentValue = matrix[i][j];        //--5
            nextValue = matrix[j][i + span];    //--11
            matrix[j][i + span] = currentValue; // 11==>5

            currentValue = nextValue;
            nextValue = matrix[i + span][i + span - j];    //--16
            matrix[i + span][i + span - j] = currentValue; // 16==>11

            currentValue = nextValue;               // 16
            nextValue = matrix[i + span - j][i];    //
            matrix[i + span - j][i] = currentValue; // 15==>16
            matrix[i][j] = nextValue;
        }
        span /= 2;
    }
}

void rotateFlip(std::vector<std::vector<int>> &matrix) {
    int rows = matrix.size();
    int cols = matrix[0].size();
    for (int row = 0; row < rows >> 1; row++) {
        for (int col = 0; col < cols; col++) {
            std::swap(matrix[row][col], matrix[rows - row - 1][col]);
        }
    }
    for (int row = 0; row < rows; row++) {
        for (int col = row; col < cols; col++) {
            std::swap(matrix[row][col], matrix[col][row]);
        }
    }
}
} // namespace common
>>>>>>> dev:cxx/algorithm/common/src/rotate.cc
